var _Container = require('component/container.js');
var _inherit = require('core/inherit.js');
var _Helper = require('third_party/tweenjs/helper.js');
var _Materials = require('global/materials.js');
var TWEEN = require('third_party/tweenjs/tween.js');

var S = require('res/style.js');
var _Event = require('component/event.js');

// ==========================
// Tip
// ==========================
function Tip(view) {
    _Container.call(this);

    this.mEvent = new _Event();
    this.addChild(this.mView = view);

    this.alpha = 0;
    this.mAlpha = _Helper.createColor();
}
_inherit(Tip, _Container);
Tip.prototype.getEvent = function () {
    return this.mEvent;
};
Tip.prototype.onFadeIn = function () {
    this.mEvent.fire('fadein', this.getId());
};
Tip.prototype.onFadeOut = function () {
    this.mEvent.fire('fadeout', this.getId());
};
Tip.prototype.onUpdate = function () {
    this.mAlpha.setAlpha(this.alpha);
};
Tip.prototype.fadeIn = function () {
    this.alpha = 0;
    return new TWEEN.Tween(this)
        .to({alpha: 1}, 0.8)
        .onUpdate(this.onUpdate)
        .onComplete(this.onFadeIn)
        .easing(TWEEN.Easing.Cubic.Out)
        .start();
};
Tip.prototype.fadeOut = function () {
    this.move = 0;
    //this.alpha = 1;
    return new TWEEN.Tween(this)
        .to({alpha: 0}, 0.2)
        .onUpdate(this.onUpdate)
        .onComplete(this.onFadeOut)
        .easing(TWEEN.Easing.Cubic.In)
        .start();
};
Tip.prototype.drawContent = function (context) {
    _Materials.globalColor(this.mAlpha.alphaColor());
    this.mView.draw(context);
    _Materials.globalColor(this.mAlpha.originalColor());
};

module.exports = Tip;